<!--
  This file is a part of the open-eBackup project.
  This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
  If a copy of the MPL was not distributed with this file, You can obtain one at
  http://mozilla.org/MPL/2.0/.
  
  Copyright (c) [2024] Huawei Technologies Co.,Ltd.
  
  THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
  EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
  MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
  -->

<lv-form [formGroup]='formGroup' [lvLabelColon]="false" class="formGroup" lvKeepRequiredWidth>
    <lv-form-item>
        <lv-form-label lvRequired>{{'protection_resource_name_label' | i18n}}</lv-form-label>
        <lv-form-control [lvErrorTip]="nameErrorTip">
            <input lv-input type="text" formControlName="name" />
        </lv-form-control>
    </lv-form-item> 
    <!-- 文件系统名称 -->
    <lv-form-item>
        <lv-form-label lvRequired>
            {{ 'protection_file_system_name_label' | i18n }}
            <i lv-icon="aui-icon-help" lv-tooltip="{{'protection_commonshare_file_system_name_tip_label'  | i18n}}"
                lvTooltipTheme="light" class="configform-constraint" lvColorState='true' lvTooltipClassName="customer-name"></i>
        </lv-form-label>
        <lv-form-control [lvErrorTip]="filesystemNameErrorTip">
            <input lv-input type="text" formControlName="filesystemName" />
        </lv-form-control>
    </lv-form-item>
    <!-- 指定备份存储单元 -->
    <lv-form-item>
        <lv-form-label lvRequired>{{'protection_commonshare_backup_storage_unit_label' | i18n}}</lv-form-label>
        <lv-form-control [lvErrorTip]="baseUtilService.requiredErrorTip">
            <lv-select [lvOptions]='backupStorageUnitOps' lvValueKey='value' formControlName='esn'
                [lvDisabled]="isModify">
            </lv-select>
        </lv-form-control>
    </lv-form-item>
    <!-- 限速策略 -->
    <lv-form-item>
        <lv-form-label>
            {{'common_limit_rate_policy_single_label' | i18n}}
            <i lv-icon="aui-icon-help" lv-tooltip="{{'common_limit_rate_policy_tip_label' | i18n}}"
            lvTooltipTheme="light" lvTooltipPosition="right" class="configform-constraint" lvColorState='true'></i>
        </lv-form-label>
        <lv-form-control>
            <lv-select [lvOptions]="qosNames" formControlName="qos_id" lvValueKey="uuid" lvShowClear>
            </lv-select>
        </lv-form-control>
    </lv-form-item>
    <!-- 共享协议 -->
    <lv-form-item>
        <lv-form-label lvRequired>{{'explore_share_protocol_label' | i18n}}</lv-form-label>
        <lv-form-control>
            <lv-checkbox-group formControlName="shareProtocol">
                <lv-group [lvGutter]="'16px'">
                    <lv-checkbox *ngFor="let item of shareProtocolOps" [lvValue]="item.value">
                        {{item.label}}
                    </lv-checkbox>
                </lv-group>
            </lv-checkbox-group>
        </lv-form-control>
    </lv-form-item>

    <!-- nfs设置 -->
    <ng-container *ngIf="includes(formGroup.value.shareProtocol,'nfs')">
        <h2 class="textDiv">{{'protection_commonshare_nfs_label' | i18n}}</h2>
        <lv-alert *ngIf="isHcsUser" lvType="info" lvClosable="false">
            {{'protection_commonshare_nfs_tips_label' | i18n}}
        </lv-alert>
        <lv-form-item>
            <lv-form-label lvRequired>{{'protection_share_path_info_label' | i18n}}</lv-form-label>
            <lv-form-control>
                <input lv-input type="text" formControlName="nfsSharePath" />
            </lv-form-control>
        </lv-form-item>
        <lv-form-item>
            <lv-form-label [lvRequired]="!isHcsUser">
                {{'protection_share_client_label' | i18n}}
                <i lv-icon="aui-icon-help" lv-tooltip="{{'protection_commonshare_whitelist_tips_label' | i18n}}"
                    lvTooltipTheme="light" class="configform-constraint" lvColorState='true'></i>
            </lv-form-label>
            <lv-form-control>
                <div formArrayName="whitelist" class="whitelist">
                    <div [formGroupName]="i" *ngFor="let item of ips; let i=index" class="mgb-ip">
                        <lv-group [lvGutter]="'10px'">
                            <lv-form-control [lvErrorTip]="whiteListErrorTip">
                                <input lv-input type="text" formControlName="ip" /></lv-form-control>
                            <ng-container *ngIf="ips.length > 1">
                                <i lv-icon="aui-icon-remove" (click)="deleteIp(i)" lvColorState='true'
                                    style="width:20px"></i>
                            </ng-container>
                        </lv-group>
                    </div>
                </div>
                <div class="tips" *ngIf="ipRepeat">
                    <i lv-icon="lv-icon-status-failed" class="error-icon"></i>
                    {{ repeatTips }}
                </div>
                <lv-group lvGutter='8px'
                    [ngClass]="{'aui-link-disabled':ips.length >= 100, 'aui-link': ips.length < 100 }"
                    (click)="addIp()">
                    <i lv-icon="aui-icon-create"></i>
                    <span class="text-middle">{{'common_add_label' | i18n}}</span>
                </lv-group>
            </lv-form-control>
        </lv-form-item>
    </ng-container>

    <!-- cifs设置 -->
    <ng-container *ngIf="includes(formGroup.value.shareProtocol,'cifs')">
        <h2 class="textDiv">{{'protection_commonshare_cifs_label' | i18n}}</h2>
        <lv-alert lvType="info" lvClosable="false" class="mgb-8">
            {{'protection_commonshare_cifs_tips_label' | i18n}}
        </lv-alert>
        <lv-form-item>
            <lv-form-label lvRequired>{{'explore_share_name_label' | i18n}}</lv-form-label>
            <lv-form-control [lvErrorTip]="cifsNameErrorTip">
                <input lv-input type="text" formControlName="shareName" />
            </lv-form-control>
        </lv-form-item>
        <lv-form-item>
            <lv-form-label lvRequired>{{'common_type_label' | i18n}}</lv-form-label>
            <lv-form-control [lvErrorTip]="baseUtilService.requiredErrorTip">
                <lv-select [lvOptions]='userTypeOptions' lvValueKey='value' formControlName='userType'>
                </lv-select>
            </lv-form-control>
        </lv-form-item>
        <ng-container
            *ngIf="formGroup.value.userType && formGroup.value.userType !== dataMap.Cifs_Domain_Client_Type.everyone.value">
            <ng-container>
                <lv-form-item>
                    <lv-form-label lvRequired>{{'common_users_label' | i18n}}</lv-form-label>
                    <lv-form-control [lvErrorTip]="baseUtilService.requiredErrorTip">
                        <lv-select [lvOptions]='userOptions' lvValueKey='value' formControlName='userNames'
                            lvMode='multiple' lvShowFilter lvShowCheckAll lvFilterKey='label' lvFilterMode='contains'>
                        </lv-select>
                        <div class="user-info">
                            <i lv-icon="lv-icon-status-info" lvColorState='true'></i>
                            <span>
                                {{'protection_file_system_user_tip_label' | i18n}}
                            </span>
                        </div>
                    </lv-form-control>
                </lv-form-item>
            </ng-container>
        </ng-container>
    </ng-container>
</lv-form>

<ng-template #clientHostTipTpl>
    <span [innerHTML]="clientHostTipLabel"></span>
</ng-template>

<ng-template #clientNetworkGroupTipTpl>
    <span [innerHTML]="clientNetworkGroupTipLabel"></span>
</ng-template>